<?php

class Landing extends Controller {
    //var $session_admin;
	function Landing()
	{
	parent::Controller();
        //$this->load->model(array('User_model','Network_model','User_admin_model'));
		$this->load->model(array('User_model','User_admin_model'));
        $this->load->helper(array('form','url'));
        $this->load->library('form_validation');	
	}
	
	function index()
	{		
        $this->load->library('session');
		 if($this->session->userdata('admin') != '')
		 {
			 redirect('admin/landing/welcome');
		 }
         
        if($this->input->post('submit')){
            $this->form_validation->set_rules('username', 'Username', 'required');
            $this->form_validation->set_rules('password', 'Password', 'required');
            if ($this->form_validation->run() == TRUE){
                $username = $this->input->post('username');
                $password = $this->input->post('password');
                
				if($this->User_admin_model->login($username, $password))
				{
					redirect('admin/landing/welcome');  
				}
				else
				{
					$data['notification'] = "Please input the correct username and password";
					unset($_POST);
				}
				
                /*if($this->User_model->login($username,md5($password))){
				    if ($this->User_model->is_admin_user(false)){
                      $this->User_model->set_admin_session();
                      redirect('admin/landing/welcome');  
                    }else{
                       $data['notification'] = 'You\'re not administrator';
                       $this->User_model->unset_user_session();
                    }
                }else{
                    $data['notification'] = $this->User_model->error_message;
                } */
            } 
        }
        //echo "<pre><font color='#999'>";print_r($this->session->userdata);echo "</font></pre>";        
        
		
		$this->load->view(TEMPLATE_NAME.'/admin/login', $data);
	}
    
	function welcome()
	{
		$this->load->library('session');
        
		 if($this->session->userdata('admin') == '')
		 {    
		     redirect('admin');
		 }
			
		 $this->load->view(TEMPLATE_NAME.'/admin/landing', $data);  
	}
	
    function login(){        
        
        $this->load->library('session');
        
		 if($this->session->userdata('admin') == '')
		 {    
		     redirect('admin');
		 }

	   $this->load->view(TEMPLATE_NAME.'/admin/login', $data);  
    }
    
    function logout(){
        $this->User_model->unset_user_session();
        redirect('admin');
    }
}

/* End of file landing.php */
/* Location: ./system/application/controllers/landing.php */
